package com.design.movieticket.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.design.movieticket.common.base.constant.Result;
import com.design.movieticket.common.base.constant.ResultStatus;
import com.design.movieticket.common.dto.XPage;
import com.design.movieticket.entity.Expend;
import com.design.movieticket.service.ExpendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@Api(tags = "支出模块")
@RestController
@RequestMapping("/expend")
public class ExpendController {
    @Resource
    private ExpendService expendService;

    /** 分页查询 */
    @ApiOperation("支出信息分页展示")
    @GetMapping("/list/page")
    public Result findExpendListByPage(Expend expend, XPage<Void> page) {
        IPage<Expend> ExpendList = expendService.page(XPage.toIPage(page), expendService.buildQuery(expend));
        return new Result(ExpendList, ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 新增或更新支出数据 */
    @ApiOperation("新增或更新支出数据")
    @PostMapping("/addOrUpdate")
    public Result addOrEditExpend(Expend expend) {
        expendService.addOrUpdateExpendInfo(expend);
        return new Result(ResultStatus.SAVE_SUCCESS.getMsg(),ResultStatus.SAVE_SUCCESS.getCode());
    }

    /** 获取支出信息 */
    @ApiOperation("获取支出信息详情")
    @GetMapping("/getExpendDetail/{id}")
    public Result getExpendDetail(@PathVariable long id){
        return new Result(expendService.getExpendDetail(id),ResultStatus.REQUEST_SUCCESS.getMsg(),ResultStatus.REQUEST_SUCCESS.getCode());
    }

    /** 删除支出信息 */
    @ApiOperation("删除支出信息")
    @PostMapping("/delExpendById/{id}")
    public Result delExpendById(@PathVariable long id){
        expendService.delExpendById(id);
        return new Result(ResultStatus.DELETE_SUCCESS.getMsg(),ResultStatus.DELETE_SUCCESS.getCode());
    }
}
